package cn.jhc.Adapter;

import java.util.ArrayList;

import cn.jhc.bean.Province;
import cn.jhc.utils.ActivityForResultRequestCode;
import cn.jhc.utils.Strings;

import com.example.shilehui.R;
import com.example.shilehui.SelectCityActivity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class SelectYearRankingUserrMeritsBookAdapter extends BaseAdapter {

	Context context;
	Activity activity;
	ArrayList<String> data;
	private LayoutInflater inflater;
	public SelectYearRankingUserrMeritsBookAdapter(Context context,
			Activity activity, ArrayList<String> data) {
		this.data = data;
		this.context = context;
		this.activity = activity;
		inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);	
	}

	@Override
	public int getCount() {
		return data.size();
	}

	@Override
	public Object getItem(int position) {
		return data.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}
	DataWrapper dataWrapper;
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			convertView = inflater.inflate(
					R.layout.select_year_ranking_merits_book_listview_item, null);
			TextView year = (TextView) convertView
					.findViewById(R.id.select_year_ranking_merits_book_listview_item_year);
			dataWrapper = new DataWrapper(year);
			convertView.setTag(dataWrapper);
		} else {
			dataWrapper = (DataWrapper) convertView.getTag();
		}
		dataWrapper.year.setText(data.get(position));
		dataWrapper.year.setOnClickListener(new ConvertViewLister(data
				.get(position)));
		return convertView;
	}
	public  final class DataWrapper {
		public  TextView year;
		public DataWrapper(TextView year) {
			this.year=year;

		}
	}
	private class ConvertViewLister implements OnClickListener {

		private String year;
		public ConvertViewLister(String year){
			this.year = year;
		}

		@Override
		public void onClick(View v) {
			Intent intent = new Intent(context, SelectCityActivity.class);
			intent.putExtra(Strings.SELECT_YEAR,year);
			intent.putExtra(Strings.SELECT_FINISH, true);
			activity.setResult(ActivityForResultRequestCode.SELECT_YEAR, intent);
			activity.finish();
		}

	}
}
